import { areaAPI, cityAPI, provinceAPI } from "@/api/place";

export default {
  namespaced: true,
  state: {
    Province: [],
    City: [],
    Area: [],
  },
  getters: {},
  mutations: {
    // 省数组
    getProvinceJs(state, province) {
      state.Province = province;
    },
    // 市数组
    getCityJs(state, city) {
      state.City = city;
    },
    getAreaJs(state, area) {
      state.Area = area;
    },
  },
  actions: {
    // 获取省
    async getProvince(context) {
      const res = await provinceAPI();
      // console.log(res.data.data);
      context.commit("getProvinceJs", res.data.data);
    },
    // 获取市
    async getCity(context, pro) {
      const res = await cityAPI(pro);
      // console.log(res);
      context.commit("getCityJs", res.data.data);
    },
    // 获取区
    async getArea(context, pro, city) {
      const res = await areaAPI(pro, city);
      console.log(res);
      context.commit("getAreaJs", res.data.data);
    },
  },
};
